package com.yanqu.road.dao.impl.activity.yearmaster;

import com.yanqu.road.dao.db.DbNameStrategy;
import com.yanqu.road.dao.impl.TempDao;
import com.yanqu.road.entity.activity.yearMaster.YearMasterConfig;

import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class YearMasterActivityDaoImpl extends TempDao {
    public static String getYearMasterConfigSql = "select * from t_s_activity_year_master where activityId = ?";

    public Map<Integer, YearMasterConfig> getYearMasterConfigMap(int activityId) {
        ResultSet rs = null;
        CallableStatement call = null;
        Map<Integer, YearMasterConfig> map  = new ConcurrentHashMap<>();
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(getYearMasterConfigSql);
            int i = 1;
            call.setInt(i++, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                YearMasterConfig yearMasterConfig = new YearMasterConfig();
                yearMasterConfig.setActivityId(rs.getInt("activityId"));
                yearMasterConfig.setLevel(rs.getInt("level"));
                yearMasterConfig.setHp(rs.getLong("hp"));
                map.put(yearMasterConfig.getLevel(),yearMasterConfig);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return map;
    }
}
